﻿Public Class FrmPropertyBill
    Public FOpenType As String
    Public FBid As String
    Private FPInfo As New BServer.FBillPrintCFG
    Private FBinfo As New BServer.FBillProperty
    Private FCinfo As New BServer.FBaseProperty
    Private FCalc As Boolean
    Private Sub ButtonX3_Click(sender As Object, e As EventArgs) Handles FCloseBox.Click
        Dispose()
    End Sub

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles FNewBox.Click
        NewBill()
    End Sub
    Private Sub NewBill()
        GetCustList()
        GetItemList()
        '-全部清空
        FBinfo = New BServer.FBillProperty
        FBinfo.FCid = -1
        FCinfo = New BServer.FBaseProperty
        FCinfo.id = -1
        FDateBox.Value = Now.Date
        FBillNoBox.Text = String.Empty
        FVerifyCodeBox.Text = String.Empty
        FSDate1Box.Value = Nothing
        FEDate1Box.Value = Nothing
        FSDate2Box.Value = Nothing
        FEDate2Box.Value = Nothing
        FSDate3Box.Value = Nothing
        FEDate3Box.Value = Nothing
        FSDate4Box.Value = Nothing
        FEDate4Box.Value = Nothing
        FQty1Box.Value = 0
        FQty2Box.Value = 0
        FQty3Box.Value = 0
        FQty4Box.Value = 0
        FPrice1Box.Value = 0
        FPrice2Box.Value = 0
        FPrice3Box.Value = 0
        FPrice4Box.Value = 0
        FDays1Box.Value = 0
        FDays2Box.Value = 0
        FDays3Box.Value = 0
        FDays4Box.Value = 0
        FAcc1Box.Value = 0
        FAcc2Box.Value = 0
        FAcc3Box.Value = 0
        FAcc4Box.Value = 0
        FAmountBigLabel.Text = "零元"
        FAmountLabel.Text = "0.00"
        FUNameBox.Text = UInfo.FRName
        FPNameBox.Text = String.Empty
        FSaveBox.Enabled = True
        CHGControls(True)
    End Sub
    Private Sub GetCustList()
        Try
            Dim TmpArr As Byte() = Nothing
            Dim ErrString As String = String.Empty
            Dim ds As New DataSet
            FNameBox.DataSource = Nothing
            FCNameBox.DataSource = Nothing
            If SControl._Bill_Prop_GetCustomList(UInfo.FSession, "*", TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox(String.Format("读取客户信息失败!{0}错误信息:无法解析返回数据!", vbCrLf))
                Return
            End If
            FCNameBox.DataSource = ds.Tables(0).DefaultView
            FCNameBox.DisplayMember = "FCName"
            FCNameBox.ValueMember = "id"
            FCNameBox.SelectedIndex = -1
            FNameBox.DataSource = ds.Tables(0).Copy.DefaultView
            FNameBox.DisplayMember = "FName"
            FNameBox.ValueMember = "id"
            FNameBox.SelectedIndex = -1
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub GetItemList()
        Try
            Dim TmpArr As Byte() = Nothing
            Dim ErrString As String = String.Empty
            Dim ds As New DataSet
            FItem1Box.DataSource = Nothing
            FItem2Box.DataSource = Nothing
            FItem3Box.DataSource = Nothing
            FItem4Box.DataSource = Nothing
            If SControl._Bill_Prop_GetItemList(UInfo.FSession, "*", TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox(String.Format("取项目列表失败!{0}错误信息:无法解析返回数据", vbCrLf))
                Return
            End If
            FItem1Box.DataSource = ds.Tables(0).DefaultView
            FItem2Box.DataSource = ds.Tables(0).Copy.DefaultView
            FItem3Box.DataSource = ds.Tables(0).Copy.DefaultView
            FItem4Box.DataSource = ds.Tables(0).Copy.DefaultView
            FItem1Box.DisplayMember = "FName"
            FItem1Box.ValueMember = "id"
            FItem2Box.DisplayMember = "FName"
            FItem2Box.ValueMember = "id"
            FItem3Box.DisplayMember = "FName"
            FItem3Box.ValueMember = "id"
            FItem4Box.DisplayMember = "FName"
            FItem4Box.ValueMember = "id"
            FItem1Box.SelectedIndex = -1
            FItem2Box.SelectedIndex = -1
            FItem3Box.SelectedIndex = -1
            FItem4Box.SelectedIndex = -1
        Catch ex As Exception

        End Try
    End Sub

#Region "窗体载入"
    Private Sub FrmPropertyBill_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Icon = My.Resources.Properties
        SControl._Base_GetBillPrintConfig(UInfo.FSession, "Property", FPInfo, "")
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Select Case FOpenType
            Case "NewBill"
                NewBill()
                FPrintBox.Enabled = False
            Case "View"
                '--取单据信息
                If FBid Is Nothing Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If CInt(FBid) <= 0 Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If GetBillInfo() = False Then
                    MsgBox("读取单据信息失败!")
                    Dispose()
                    Return
                End If
                '-预留
                If FBinfo.FVid = Nothing Then
                    '-没审核
                    FSaveBox.Text = "收费"
                    FSaveBox.Image = My.Resources.money
                    FPrintBox.Enabled = False
                ElseIf FBinfo.FVid = UInfo.id Then
                    FSaveBox.Enabled = False
                    FPrintBox.Enabled = True
                Else
                    '--其它人的单据
                    FSaveBox.Enabled = False
                    FPrintBox.Enabled = False
                End If
            Case "Modify"
                '--取单据信息
                If FBid Is Nothing Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If CInt(FBid) <= 0 Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If GetBillInfo() = False Then
                    MsgBox("读取单据信息失败!")
                    Dispose()
                    Return
                End If
                '--可修改的项目
                CHGControls(True)
                GetItemList()
                FCalc = True
            Case Else
                MsgBox("参数错误")
                Dispose()
                Return
        End Select

    End Sub
#End Region

#Region "点击打印按钮"
    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles FPrintBox.Click

        '--读取打印参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        PrintDialog1.PrinterSettings = ps.PrinterSettings
        '--弹出打印设置窗口
        If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        '--更新打印参数
        PrintDialog1.AllowPrintToFile = False
        ps.PrinterSettings = PrintDialog1.PrinterSettings
        '--保存打印参数
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Property", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        '--增加打印次数
        If SControl._Bill_Prop_AddPrintCount(UInfo.FSession, FBinfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        Label1.Text = "打印次数:" & FBinfo.FPCount
        '---显示预览
        PrintDocument1.DefaultPageSettings = ps
        PrintDocument1.DocumentName = "收款收据(一)"
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
        '--增加打印次数

    End Sub
#End Region

#Region "页面设置"
    Private Sub ButtonX5_Click(sender As Object, e As EventArgs) Handles FPageSetBox.Click
        '--读取参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        '--显示页面设置窗口
        PageSetupDialog1.ShowDialog()
        '--保存参数
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        '---------参数赋值
        FPInfo.FMarginB = ps.Margins.Bottom
        FPInfo.FMarginT = ps.Margins.Top
        FPInfo.FMarginR = ps.Margins.Right
        FPInfo.FMarginL = ps.Margins.Left
        If ps.Landscape = False Then
            FPInfo.FPaperDirect = "V"
        Else
            FPInfo.FPaperDirect = "H"
        End If
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Property", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
    End Sub
#End Region

#Region "打印"
    Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Try
            '--设置页面参数
            '--A4纸
            PrintDocument1.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize With {.PaperName = "A4", .Height = 1169, .Width = 827}
            '--页面设置
            PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
            '--打印机设置
            PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
            '--设置以毫米为单位
            e.Graphics.PageUnit = GraphicsUnit.Millimeter

            '--定义变量
            Dim g As Graphics = e.Graphics 'graphics对象
            Dim FX As Integer = PrintDocument1.DefaultPageSettings.Margins.Left  '横向偏移量
            Dim FY As Integer = PrintDocument1.DefaultPageSettings.Margins.Top  '纵向偏移量
            Dim FNT As New Font("宋体", 20)
            '--打印标题
            g.DrawString(FCaptionLabel.Text, FNT, Brushes.Black, New Point With {.X = 90 + FX, .Y = 0 + FY})
            '--标题下两条线
            g.PageUnit = GraphicsUnit.Display
            g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(75 + FX), FControl.CalcInch(8 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(8 + FY))
            g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(75 + FX), FControl.CalcInch(9 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(9 + FY))
            '--日期
            e.Graphics.PageUnit = GraphicsUnit.Millimeter
            FNT = New Font("宋体", 12)
            g.DrawString("开票日期:" & FDateBox.Value.ToString("yyyy年MM月dd日"), FNT, Brushes.Black, New PointF With {.X = 80 + FX, .Y = 10 + FY})
            '--交款单位,编号
            g.DrawString("交款单位:" & FNameBox.Text, FNT, Brushes.Black, New PointF(20 + FX, 15 + FY))
            g.DrawString("编    号:" & FBillNoBox.Text, FNT, Brushes.Black, New PointF(135 + FX, 15 + FY))
            '--交款人,验证码
            g.DrawString("交 款 人:" & FCNameBox.Text.Trim, FNT, Brushes.Black, New Point(20 + FX, 22 + FY))
            g.DrawString("验 证 码:" & FVerifyCodeBox.Text.Trim, FNT, Brushes.Black, New Point(135 + FX, 22 + FY))
            '--外框和格线
            g.PageUnit = GraphicsUnit.Display
            Dim rect As New Rectangle(New Point(FControl.CalcInch(19 + FX), FControl.CalcInch(28 + FY)), New Size(FControl.CalcInch(164), FControl.CalcInch(42.2)))
            g.DrawRectangle(Pens.Black, rect)
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(35 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(42 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(49 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(49 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(56 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(56 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(63 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(63 + FY))
            '-竖线
            g.DrawLine(Pens.Black, FControl.CalcInch(49 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(49 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(92 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(92 + FX), FControl.CalcInch(63 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(111 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(111 + FX), FControl.CalcInch(63 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(131 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(131 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(155 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(155 + FX), FControl.CalcInch(70 + FY))
            '--标题栏
            g.PageUnit = GraphicsUnit.Millimeter
            FNT = New Font("宋体", 12)
            '-右侧记账联标志
            g.DrawString("①", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 39 + FY})
            g.DrawString("记", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 45 + FY})
            g.DrawString("账", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 50 + FY})
            g.DrawString("联", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 55 + FY})
            '-项目
            g.DrawString("项目", FNT, Brushes.Black, New PointF With {.X = 30 + FX, .Y = 30 + FY})
            '-收费区间
            g.DrawString("收费区间", FNT, Brushes.Black, New PointF With {.X = 62 + FX, .Y = 30 + FY})
            '-平米数
            g.DrawString("平米数", FNT, Brushes.Black, New PointF With {.X = 95 + FX, .Y = 30 + FY})
            '-单价
            g.DrawString("元/天.平", FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 30 + FY})
            '-天数
            g.DrawString("天数", FNT, Brushes.Black, New PointF With {.X = 139 + FX, .Y = 30 + FY})
            '-金额
            g.DrawString("金额", FNT, Brushes.Black, New PointF With {.X = 165 + FX, .Y = 30 + FY})
            '-----分录
            '--第一行
            '-项目
            If Not FItem1Box.Text Is Nothing Then
                If FItem1Box.Text.Trim <> String.Empty Then
                    g.DrawString(FItem1Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 36.5 + FY})
                    '-收费区间
                    g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate1Box.Value, FEDate1Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 36.5 + FY})
                    '-平米数
                    g.DrawString(FQty1Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 36.5 + FY})
                    '-单价
                    g.DrawString(FPrice1Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 36.5 + FY})
                    '-天数
                    g.DrawString(FDays1Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 36.5 + FY})
                    '-金额
                    g.DrawString(FAcc1Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 36.5 + FY})
                End If
            End If


            '--第二行
            If Not FItem2Box.Text Is Nothing Then
                If FItem2Box.Text.Trim <> String.Empty Then
                    '-项目
                    g.DrawString(FItem1Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 43.5 + FY})
                    '-收费区间
                    g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate2Box.Value, FEDate2Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 43.5 + FY})
                    '-平米数
                    g.DrawString(FQty2Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 43.5 + FY})
                    '-单价
                    g.DrawString(FPrice2Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 43.5 + FY})
                    '-天数
                    g.DrawString(FDays2Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 43.5 + FY})
                    '-金额
                    g.DrawString(FAcc2Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 43.5 + FY})

                End If
            End If


            '--第三行
            '-项目
            If Not FItem3Box.Text Is Nothing Then
                If FItem3Box.Text.Trim <> String.Empty Then
                    g.DrawString(FItem3Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 50.5 + FY})
                    '-收费区间
                    g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate3Box.Value, FEDate3Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 50.5 + FY})
                    '-平米数
                    g.DrawString(FQty3Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 50.5 + FY})
                    '-单价
                    g.DrawString(FPrice3Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 50.5 + FY})
                    '-天数
                    g.DrawString(FDays3Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 50.5 + FY})
                    '-金额
                    g.DrawString(FAcc3Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 50.5 + FY})
                End If
            End If


            '--第四行
            If Not FItem4Box.Text Is Nothing Then
                If FItem4Box.Text.Trim <> String.Empty Then
                    g.DrawString(FItem4Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 57.5 + FY})
                    '-收费区间
                    g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate4Box.Value, FEDate4Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 57.5 + FY})
                    '-平米数
                    g.DrawString(FQty4Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 57.5 + FY})
                    '-单价
                    g.DrawString(FPrice4Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 57.5 + FY})
                    '-天数
                    g.DrawString(FDays4Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 57.5 + FY})
                    '-金额
                    g.DrawString(FAcc4Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 57.5 + FY})

                End If
            End If
            '-项目

            '--合计行
            g.DrawString("合计(大写):", FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 64.5 + FY})
            g.DrawString(FAmountBigLabel.Text, FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 64.5 + FY})
            g.DrawString("合计:", FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 64.5 + FY})
            g.DrawString(FAmountLabel.Text, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 64.5 + FY})
            '--表尾信息
            g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FUNameBox.Text, SControl.Base_Org_getOrgName(FBinfo.FOrgid)), FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 79 + FY})
            '---------------------------------------------第一段结束--------------------------------------------------


            FY += 100
            FNT = New Font("宋体", 20)
            '--打印标题
            g.DrawString(FCaptionLabel.Text, FNT, Brushes.Black, New Point With {.X = 90 + FX, .Y = 0 + FY})
            '--标题下两条线
            g.PageUnit = GraphicsUnit.Display
            g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(75 + FX), FControl.CalcInch(8 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(8 + FY))
            g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(75 + FX), FControl.CalcInch(9 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(9 + FY))
            '--日期
            e.Graphics.PageUnit = GraphicsUnit.Millimeter
            FNT = New Font("宋体", 12)
            g.DrawString("开票日期:" & FDateBox.Value.ToString("yyyy年MM月dd日"), FNT, Brushes.Black, New PointF With {.X = 80 + FX, .Y = 10 + FY})
            '--交款单位,编号
            g.DrawString("交款单位:" & FNameBox.Text, FNT, Brushes.Black, New PointF(20 + FX, 15 + FY))
            g.DrawString("编    号:" & FBillNoBox.Text, FNT, Brushes.Black, New PointF(135 + FX, 15 + FY))
            '--交款人,验证码
            g.DrawString("交 款 人:" & FCNameBox.Text.Trim, FNT, Brushes.Black, New Point(20 + FX, 22 + FY))
            g.DrawString("验 证 码:" & FVerifyCodeBox.Text.Trim, FNT, Brushes.Black, New Point(135 + FX, 22 + FY))
            '--外框和格线
            g.PageUnit = GraphicsUnit.Display
            rect = New Rectangle(New Point(FControl.CalcInch(19 + FX), FControl.CalcInch(28 + FY)), New Size(FControl.CalcInch(164), FControl.CalcInch(42.2)))
            g.DrawRectangle(Pens.Black, rect)
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(35 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(42 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(49 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(49 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(56 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(56 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(63 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(63 + FY))
            '-竖线
            g.DrawLine(Pens.Black, FControl.CalcInch(49 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(49 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(92 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(92 + FX), FControl.CalcInch(63 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(111 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(111 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(131 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(131 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(155 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(155 + FX), FControl.CalcInch(70 + FY))
            '--标题栏
            g.PageUnit = GraphicsUnit.Millimeter
            FNT = New Font("宋体", 12)
            '-右侧记账联标志
            g.DrawString("②", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 39 + FY})
            g.DrawString("客", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 45 + FY})
            g.DrawString("户", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 50 + FY})
            g.DrawString("联", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 55 + FY})
            '-项目
            g.DrawString("项目", FNT, Brushes.Black, New PointF With {.X = 30 + FX, .Y = 30 + FY})
            '-收费区间
            g.DrawString("收费区间", FNT, Brushes.Black, New PointF With {.X = 62 + FX, .Y = 30 + FY})
            '-平米数
            g.DrawString("平米数", FNT, Brushes.Black, New PointF With {.X = 95 + FX, .Y = 30 + FY})
            '-单价
            g.DrawString("元/天.平", FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 30 + FY})
            '-天数
            g.DrawString("天数", FNT, Brushes.Black, New PointF With {.X = 139 + FX, .Y = 30 + FY})
            '-金额
            g.DrawString("金额", FNT, Brushes.Black, New PointF With {.X = 165 + FX, .Y = 30 + FY})
            '-----分录
            '--第一行
            '-项目
            g.DrawString(FItem1Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 36.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate1Box.Value, FEDate1Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 36.5 + FY})
            '-平米数
            g.DrawString(FQty1Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 36.5 + FY})
            '-单价
            g.DrawString(FPrice1Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 36.5 + FY})
            '-天数
            g.DrawString(FDays1Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 36.5 + FY})
            '-金额
            g.DrawString(FAcc1Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 36.5 + FY})

            '--第二行
            '-项目
            g.DrawString(FItem1Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 43.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate2Box.Value, FEDate2Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 43.5 + FY})
            '-平米数
            g.DrawString(FQty2Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 43.5 + FY})
            '-单价
            g.DrawString(FPrice2Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 43.5 + FY})
            '-天数
            g.DrawString(FDays2Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 43.5 + FY})
            '-金额
            g.DrawString(FAcc2Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 43.5 + FY})

            '--第三行
            '-项目
            g.DrawString(FItem3Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 50.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate3Box.Value, FEDate3Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 50.5 + FY})
            '-平米数
            g.DrawString(FQty3Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 50.5 + FY})
            '-单价
            g.DrawString(FPrice3Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 50.5 + FY})
            '-天数
            g.DrawString(FDays3Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 50.5 + FY})
            '-金额
            g.DrawString(FAcc3Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 50.5 + FY})

            '--第四行
            '-项目
            g.DrawString(FItem4Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 57.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate4Box.Value, FEDate4Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 57.5 + FY})
            '-平米数
            g.DrawString(FQty4Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 57.5 + FY})
            '-单价
            g.DrawString(FPrice4Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 57.5 + FY})
            '-天数
            g.DrawString(FDays4Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 57.5 + FY})
            '-金额
            g.DrawString(FAcc4Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 57.5 + FY})

            '--合计行
            g.DrawString("合计(大写):", FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 64.5 + FY})
            g.DrawString(FAmountBigLabel.Text, FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 64.5 + FY})
            g.DrawString("合计:", FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 64.5 + FY})
            g.DrawString(FAmountLabel.Text, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 64.5 + FY})
            '--表尾信息
            g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FUNameBox.Text, SControl.Base_Org_getOrgName(FBinfo.FOrgid)), FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 79 + FY})
            'g.DrawString("收款单位:", FNT, Brushes.Black, New PointF With {.X = 191 + FX, .Y = 72 + FY})
            '---------------------------------------------第二段结束-------------------------------------------------


            FY += 100
            FNT = New Font("宋体", 20)
            '--打印标题
            g.DrawString(FCaptionLabel.Text, FNT, Brushes.Black, New Point With {.X = 90 + FX, .Y = 0 + FY})
            '--标题下两条线
            g.PageUnit = GraphicsUnit.Display
            g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(75 + FX), FControl.CalcInch(8 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(8 + FY))
            g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(75 + FX), FControl.CalcInch(9 + FY), FControl.CalcInch(140 + FX), FControl.CalcInch(9 + FY))
            '--日期
            e.Graphics.PageUnit = GraphicsUnit.Millimeter
            FNT = New Font("宋体", 12)
            g.DrawString("开票日期:" & FDateBox.Value.ToString("yyyy年MM月dd日"), FNT, Brushes.Black, New PointF With {.X = 80 + FX, .Y = 10 + FY})
            '--交款单位,编号
            g.DrawString("交款单位:" & FNameBox.Text, FNT, Brushes.Black, New PointF(20 + FX, 15 + FY))
            g.DrawString("编    号:" & FBillNoBox.Text, FNT, Brushes.Black, New PointF(135 + FX, 15 + FY))
            '--交款人,验证码
            g.DrawString("交 款 人:" & FCNameBox.Text.Trim, FNT, Brushes.Black, New Point(20 + FX, 22 + FY))
            g.DrawString("验 证 码:" & FVerifyCodeBox.Text.Trim, FNT, Brushes.Black, New Point(135 + FX, 22 + FY))
            '--外框和格线
            g.PageUnit = GraphicsUnit.Display
            rect = New Rectangle(New Point(FControl.CalcInch(19 + FX), FControl.CalcInch(28 + FY)), New Size(FControl.CalcInch(164), FControl.CalcInch(42.2)))
            g.DrawRectangle(Pens.Black, rect)
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(35 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(42 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(49 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(49 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(56 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(56 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(19 + FX), FControl.CalcInch(63 + FY), FControl.CalcInch(183 + FX), FControl.CalcInch(63 + FY))
            '-竖线
            g.DrawLine(Pens.Black, FControl.CalcInch(49 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(49 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(92 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(92 + FX), FControl.CalcInch(63 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(111 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(111 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(131 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(131 + FX), FControl.CalcInch(70 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(155 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(155 + FX), FControl.CalcInch(70 + FY))
            '--标题栏
            g.PageUnit = GraphicsUnit.Millimeter
            FNT = New Font("宋体", 12)
            '-右侧记账联标志
            g.DrawString("③", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 39 + FY})
            g.DrawString("其", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 45 + FY})
            g.DrawString("它", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 50 + FY})
            g.DrawString("联", FNT, Brushes.Black, New PointF With {.X = 185 + FX, .Y = 55 + FY})
            '-项目
            g.DrawString("项目", FNT, Brushes.Black, New PointF With {.X = 30 + FX, .Y = 30 + FY})
            '-收费区间
            g.DrawString("收费区间", FNT, Brushes.Black, New PointF With {.X = 62 + FX, .Y = 30 + FY})
            '-平米数
            g.DrawString("平米数", FNT, Brushes.Black, New PointF With {.X = 95 + FX, .Y = 30 + FY})
            '-单价
            g.DrawString("元/天.平", FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 30 + FY})
            '-天数
            g.DrawString("天数", FNT, Brushes.Black, New PointF With {.X = 139 + FX, .Y = 30 + FY})
            '-金额
            g.DrawString("金额", FNT, Brushes.Black, New PointF With {.X = 165 + FX, .Y = 30 + FY})
            '-----分录
            '--第一行
            '-项目
            g.DrawString(FItem1Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 36.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate1Box.Value, FEDate1Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 36.5 + FY})
            '-平米数
            g.DrawString(FQty1Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 36.5 + FY})
            '-单价
            g.DrawString(FPrice1Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 36.5 + FY})
            '-天数
            g.DrawString(FDays1Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 36.5 + FY})
            '-金额
            g.DrawString(FAcc1Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 36.5 + FY})

            '--第二行
            '-项目
            g.DrawString(FItem1Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 43.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate2Box.Value, FEDate2Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 43.5 + FY})
            '-平米数
            g.DrawString(FQty2Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 43.5 + FY})
            '-单价
            g.DrawString(FPrice2Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 43.5 + FY})
            '-天数
            g.DrawString(FDays2Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 43.5 + FY})
            '-金额
            g.DrawString(FAcc2Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 43.5 + FY})

            '--第三行
            '-项目
            g.DrawString(FItem3Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 50.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate3Box.Value, FEDate3Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 50.5 + FY})
            '-平米数
            g.DrawString(FQty3Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 50.5 + FY})
            '-单价
            g.DrawString(FPrice3Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 50.5 + FY})
            '-天数
            g.DrawString(FDays3Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 50.5 + FY})
            '-金额
            g.DrawString(FAcc3Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 50.5 + FY})

            '--第四行
            '-项目
            g.DrawString(FItem4Box.Text.Trim, FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 57.5 + FY})
            '-收费区间
            g.DrawString(String.Format("{0:yyyy.M.d}-{1:yyyy.M.d}", FSDate4Box.Value, FEDate4Box.Value), FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 57.5 + FY})
            '-平米数
            g.DrawString(FQty4Box.Value, FNT, Brushes.Black, New PointF With {.X = 92 + FX, .Y = 57.5 + FY})
            '-单价
            g.DrawString(FPrice4Box.Value, FNT, Brushes.Black, New PointF With {.X = 112 + FX, .Y = 57.5 + FY})
            '-天数
            g.DrawString(FDays4Box.Value, FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 57.5 + FY})
            '-金额
            g.DrawString(FAcc4Box.Value, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 57.5 + FY})

            '--合计行
            g.DrawString("合计(大写):", FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 64.5 + FY})
            g.DrawString(FAmountBigLabel.Text, FNT, Brushes.Black, New PointF With {.X = 50 + FX, .Y = 64.5 + FY})
            g.DrawString("合计:", FNT, Brushes.Black, New PointF With {.X = 132 + FX, .Y = 64.5 + FY})
            g.DrawString(FAmountLabel.Text, FNT, Brushes.Black, New PointF With {.X = 156 + FX, .Y = 64.5 + FY})
            '--表尾信息
            g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FUNameBox.Text, SControl.Base_Org_getOrgName(FBinfo.FOrgid)), FNT, Brushes.Black, New PointF With {.X = 20 + FX, .Y = 79 + FY})
        Catch ex As Exception
            MsgBox("生成打印模板失败!" & ex.Message)
            e.Cancel = True
        End Try
    End Sub
#End Region


    Private Sub ButtonX2_Click(sender As Object, e As EventArgs) Handles FSaveBox.Click
        SaveBill()
    End Sub


End Class